#coding=utf-8
import time,sys
from stockdb.misc import *

def addjump(code):
    s = find_stock(code)
    for td in s.tds:
        pre = td.pre
        
        if not pre:
            #return
            try:    
                assert td.date == s.ipo, td.date.isoformat()
            except AssertionError, e:
                print e
                print 'ipo:',s.ipo
                if raw_input('continue?') != 'y': 
                    sys.exit(1)
                else:
                     p = td.price
                     p.change = None
                     sess.commit()
                     sess.close()
                     return  
                    
            pclose = s.iprice
            if not pclose:
                sess.commit()
                sess.close()
                return
        else:    
            pclose = pre.close
        
        p = td.price
        p.jump = (p.open - pclose)*100 / pclose
        
        #sess.save(p)
    
    sess.commit()
    sess.close()
    #time.sleep(0.1)
    
if __name__  == '__main__':    
    cs = get_stcodes()    
    for c in cs[540:]:
        print c
        addjump(c)
